package day20171222;

import com.mysql.cj.jdbc.Driver;

import java.io.File;
import java.security.Key;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by 123 on 2017/12/22.
 */
public class HomeWork {
    public static void main(String[] args) {

        Map<String, Integer> map = new HashMap();//存放已交学生学号，Integer一开始统一设置为0

        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        String sql = "SELECT stu_no FROM t_students";//从数据库表里面得到学生的学号
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            try {
                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                        "root",
                        "123456");
                statement = connection.createStatement();
                resultSet = statement.executeQuery(sql);

                while (resultSet.next()) {
                    map.put(resultSet.getString(1), 0);//将从数据库得到的学号存入map集合里面
                    //    System.out.println(map.get(resultSet.getString(1)));
                }

            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        String path = "E:\\homework";//存放学生作业的文件夹
        File file = new File(path);

        for (File f : file.listFiles()) {
            if (f.isFile()) {
                System.out.println("文件" + f.getName());
//                Matcher matcher= Pattern.compile("信本1班(\\S+)实验")
//                        .matcher(f.getName());//正则表达式得到学号加姓名

             //   String line=matcher.group(1);//得到学号

                String line=f.getName().substring(24,33);
                System.out.println(line);

                if (map.get(line) == null) {
                } else {
                    map.put(line, (map.get(line).intValue() + 1));//将交了作业的人map的value加一
                }

                //方法一：循环map里面的每一对键值对，然后获取key和value
                for (Map.Entry<String,Integer>vo:map.entrySet()){
                    while (vo.getValue()==0){
                        System.out.println(vo.getKey());
                    }

                }










            }
        }
    }
}
